package com.ruihu.api.module.business.task.controller;

import com.ruihu.admin.common.anno.NoValidPrivilege;
import com.ruihu.admin.common.anno.OperateLog;
import com.ruihu.admin.common.controller.BaseController;
import com.ruihu.admin.common.domain.ResponseDTO;
import com.ruihu.admin.constant.SwaggerTagConst;
import com.ruihu.admin.module.business.tasknode.domain.dto.GetPoleGroupFileRequestDTO;
import com.ruihu.admin.module.business.tasknode.domain.dto.SubTaskNodeInstUpdateDTO;
import com.ruihu.admin.module.business.tasknode.domain.dto.TaskNodeFileDeleteDTO;
import com.ruihu.admin.module.business.tasknode.domain.vo.AIImageResultVO;
import com.ruihu.admin.module.business.tasknode.domain.vo.SubTaskNodeInstVO;
import com.ruihu.admin.module.business.tasknode.domain.vo.TaskNodeFileVO;
import com.ruihu.admin.module.business.tasknode.service.SubTaskNodeInstService;
import com.ruihu.admin.module.business.tasknode.service.TaskNodeFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * [ 子任务环节实例表 ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2022-08-30 19:43:58
 * @since JDK1.8
 */
@RestController(value = "subTaskNodeInstApiContrller")
@Api(tags = {SwaggerTagConst.Mobile.SUB_TASK_API})
@OperateLog
public class SubTaskNodeInstController extends BaseController {

    @Autowired
    private SubTaskNodeInstService subTaskNodeInstService;

    @Autowired
    private TaskNodeFileService taskNodeFileService;

    @ApiOperation(value = "获取子任务环节数据",notes = "@author Tony")
    @PostMapping("/api/subTaskNodeInst/{subTaskId}/{taskNodeInstId}/query")
    @NoValidPrivilege
    public ResponseDTO<SubTaskNodeInstVO> query(@PathVariable("subTaskId")  Long subTaskId,
                                                @PathVariable("taskNodeInstId") Long taskNodeInstId){
        return this.subTaskNodeInstService.queryTaskNodeInstData(subTaskId, taskNodeInstId);
    }

    @ApiOperation(value = "跳转到某个环节",notes = "@author Tony")
    @PostMapping("/api/subTaskNodeInst/{subTaskId}/{taskNodeInstId}/jump")
    @NoValidPrivilege
    public ResponseDTO<SubTaskNodeInstVO> jumpTo(@PathVariable("subTaskId")  Long subTaskId,
                                                @PathVariable("taskNodeInstId") Long taskNodeInstId){
        return this.subTaskNodeInstService.queryTaskNodeInstData(subTaskId, taskNodeInstId);
    }

    @ApiOperation(value = "进入到下一步环节",notes = "@author Tony")
    @PostMapping("/api/subTaskNodeInst/next")
    @NoValidPrivilege
    public ResponseDTO<SubTaskNodeInstVO> nextTaskNode(@RequestBody @Validated SubTaskNodeInstUpdateDTO updateDTO){
        return this.subTaskNodeInstService.nextTaskNode(updateDTO);
    }

    @ApiOperation(value = "进入到上一步环节",notes = "@author Tony")
    @PostMapping("/api/subTaskNodeInst/{subTaskId}/{taskNodeInstId}/prev")
    @NoValidPrivilege
    public ResponseDTO<SubTaskNodeInstVO> prevTaskNode(@PathVariable("subTaskId")  Long subTaskId,
                                                       @PathVariable("taskNodeInstId") Long taskNodeInstId){
        return this.subTaskNodeInstService.prevTaskNode(subTaskId, taskNodeInstId);
    }

    @ApiOperation(value = "完成子任务",notes = "@author Tony")
    @PostMapping("/api/{subTaskId}/{taskNodeInstId}/finish")
    @NoValidPrivilege
    public ResponseDTO<String> finishTask(@PathVariable("subTaskId") Long subTaskId,
                                          @PathVariable("taskNodeInstId") Long taskNodeInstId){
        return this.subTaskNodeInstService.finishTask(subTaskId);
    }


    @ApiOperation(value = "跳过环节",notes = "@author Tony")
    @PostMapping("/api/subTaskNodeInst/{subTaskId}/{taskNodeInstId}/skip")
    @NoValidPrivilege
    public ResponseDTO<SubTaskNodeInstVO> skipTaskNode(@PathVariable("subTaskId")  Long subTaskId,
                                                       @PathVariable("taskNodeInstId") Long taskNodeInstId){
        return this.subTaskNodeInstService.skipTaskNode(subTaskId, taskNodeInstId);
    }

    @ApiOperation(value="修改子任务环节数据",notes = "@author Tony")
    @PostMapping("/api/subTaskNodeInst/update")
    @NoValidPrivilege
    public ResponseDTO<String> update(@RequestBody @Validated SubTaskNodeInstUpdateDTO updateDTO){
        return subTaskNodeInstService.update(updateDTO);
    }

    @ApiOperation(value="删除子任务节点附件", notes = "@author Tony")
    @PostMapping("/api/subTaskNodeInst/delete")
    @NoValidPrivilege
    public ResponseDTO<String> deleteFile(@RequestBody TaskNodeFileDeleteDTO taskNodeFileDeleteDTO) {
        return this.taskNodeFileService.deleteFile(taskNodeFileDeleteDTO);
    }

    @ApiOperation(value = "挂起子任务",notes = "@author Tony")
    @PostMapping("/api/task/subtask/hang")
    @NoValidPrivilege
    public ResponseDTO<Long> hangSubTask(@RequestBody @Validated SubTaskNodeInstUpdateDTO updateDTO) {
        return this.subTaskNodeInstService.hangSubTask(updateDTO);
    }

    @ApiOperation(value = "获取子任务环节附件", notes = "@author Tony")
    @PostMapping("/api/subTaskNodeInst/{subTaskNodeInstId}/{processRelationId}/file")
    @NoValidPrivilege
    public ResponseDTO<List<TaskNodeFileVO>> getTaskNodeFileList(@PathVariable("subTaskNodeInstId")  Long subTaskNodeInstId,
                                                             @PathVariable("processRelationId") Long processRelationId) {
        return this.subTaskNodeInstService.getTaskNodeFileList(subTaskNodeInstId, processRelationId);
    }

    @ApiOperation(value = "获取AI接口极组照片", notes = "@author Tony")
    @PostMapping("/api/subTaskNodeInst/interface/file")
    @NoValidPrivilege
    public ResponseDTO<String> getSubTaskPoleGroupFilesFromAI(@RequestBody @Validated GetPoleGroupFileRequestDTO getPoleGroupFileRequest) {
        return this.subTaskNodeInstService.getSubTaskPoleGroupFilesFromAI(getPoleGroupFileRequest);
    }

    @ApiOperation(value = "获取极组附件", notes = "@author Tony")
    @PostMapping("/api/subTaskNodeInst/file")
    @NoValidPrivilege
    public ResponseDTO<AIImageResultVO> getSubTaskPoleGroupFiles(@RequestBody @Validated GetPoleGroupFileRequestDTO getPoleGroupFileRequest) {
        return this.subTaskNodeInstService.getSubTaskPoleGroupFiles(getPoleGroupFileRequest);
    }
}
